using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace GemTowerDefence.Towers
{
  public class Missile : Sprite
  {
    private decimal _age;

    public Missile(Texture2D tex, Vector2 pos)
      : base(tex, pos)
    {
    }

    public Missile(Texture2D missileTexture, Vector2 position, float rotation, int speed, int damage)
      : base(missileTexture, position)
    {
      Rotation = rotation;
      Speed = speed;
      Damage = damage;
      Velocity = Vector2.Transform(new Vector2(0, -speed), Matrix.CreateRotationZ(rotation));
    }

    public Missile(Texture2D texture, Vector2 position, Vector2 velocity, int speed, int damage)
      : base(texture, position)
    {
      Damage = damage;
      Speed = speed;
      Velocity = velocity * speed;
    }

    public int Speed { get; private set; }
    public int Damage { get; private set; }

    public bool IsDead()
    {
      return _age > 100;
    }

    public void Kill()
    {
      _age = 200;
    }

    public void SetRotation(float value)
    {
      Rotation = value;
      Velocity = Vector2.Transform(new Vector2(0, -Speed), Matrix.CreateRotationZ(Rotation));
    }

    public override void Update(GameTime gameTime)
    {
      _age++;
      Position += Velocity;
      base.Update(gameTime);
    }

  }
}